package com.cl.erp_2301.controller;

import com.cl.erp_2301.dto.DataDTO;
import com.cl.erp_2301.dto.DepartmentDTO;
import com.cl.erp_2301.entity.Department;
import com.cl.erp_2301.Service.DepartmentService;
import com.cl.erp_2301.util.Result;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/v2")
public class DepartmentController {
    @Resource
    private DepartmentService departmentService;

    @ResponseBody
    @RequestMapping("/dep/listByPage")
    public Result listByPage(Integer page, Integer rows){
        Page<Object> page1= PageHelper.startPage(page,rows);
        List<DepartmentDTO> departmentDTOList=departmentService.listByPage();
        DataDTO dataDTO=new DataDTO<>();
        dataDTO.setRows(departmentDTOList);
        dataDTO.setTotal(page1.getTotal());
        return Result.ok(dataDTO);
    }
    @ResponseBody
    @RequestMapping("/dep/add")
    public Result add(@RequestParam("name") String name,@RequestParam("tele")String tele){
        DepartmentDTO departmentDTO=new DepartmentDTO();
        departmentDTO.setName(name);
        departmentDTO.setTele(tele);
        departmentService.add(departmentDTO);
        return Result.ok();
    }

}
